
def list_change(l1):
    for x in l1:
        if x != "":
            list1.append(int(x))
   # print(list1)
    return list1


def ad(l1, l2):
 #   print(list3,list4)
    result = []
    for x in range(1, l1[0] + l2[0] + 1):
        if len(l1) > 2 and len(l2) > 2:
            if l1[2] == l2[2]:
                result.append(l1.pop(1) + l2.pop(1))
                l2.pop(1)
                result.append(l1.pop(1))
            elif l1[2] < l2[2]:
                result.append(l2.pop(1))
                result.append(l2.pop(1))
            else:
                result.append(l1.pop(1))
                result.append(l1.pop(1))
        elif len(l1) > 2:
            result.append(l1.pop(1))
            result.append(l1.pop(1))
        elif len(l2) > 2 :
            result.append(l2.pop(1))
            result.append(l2.pop(1))
    return result


def mu(l3, l4):
   # print(list1,list2)
    result2, result1, result0, result = [], [], [], []
    for x in range(1, l3[0] + 1):
        for y in range(1, l4[0] + 1):
            result0.append(l3[2 * x - 1] * l4[2 * y - 1])
            result0.append(l3[2 * x] + l4[2 * y])
    for x in range(0, int(len(result0) / 2)):
        result1.append(result0.pop(0))
        result2.append(result0.pop(0))
    for x in range(len(result2)):
        if len(result2) != 0:
            a = result2.index(max(result2))
            result.append(result1.pop(a))
            result.append(result2.pop(a))
        #    print(result)
    return result

if __name__ == "__main__":
    l1 = input().split(" ")
    list1, list2 = [], []

    list3 = list1
    list4 = list2
    list1 = list_change(l1)
    for x in range(0, 2 * list1[0] + 1):
        list2.append(list1.pop(0))

    print(list1,list2)
    mul = mu(list1, list2)
    add = ad(list3, list4)

    a = " ".join([str (i) for i in add])
    m = " ".join([str (i) for i in mul])
    print(a)
    print(m)
